# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgname=tmux-git
pkgver=2.1.144.g78a00c8
pkgrel=1
pkgdesc='A terminal multiplexer'
url='http://tmux.github.io/'
arch=('i686' 'x86_64')
license=('BSD')
provides=('tmux')
conflicts=('tmux')
depends=('ncurses' 'libevent')
makedepends=('git' 'ncurses-devel' 'libevent-devel')
source=("${pkgname}"::'git+https://github.com/tmux/tmux.git'
        'msys-platform.patch'
        'no-check-dirs-permission.patch'
        'cwd-param-mod.patch')
md5sums=('SKIP'
         'b175ece57d04168245f63dbf51f87cd0'
         'fa2ad87bf927d9a6ecf846557ab0cda6'
         'b48e96acc4e8436101e4b90622a73c03')

pkgver() {
  cd "${srcdir}"/$pkgname
  git describe --tags | sed -e 's|-|.|g' -e 's|v||g'
}

prepare() {
  cd "${srcdir}"/$pkgname
  patch -p1 -i "${srcdir}"/msys-platform.patch
  patch -p0 -i "${srcdir}"/no-check-dirs-permission.patch
  patch -p1 -i "${srcdir}"/cwd-param-mod.patch
  cp osdep-cygwin.c osdep-msys.c

  msg2 "Running autogen.sh"
  ./autogen.sh
}

build() {
  cd "${srcdir}"/$pkgname
  ./configure \
    --prefix=/usr \
    --sysconfdir=/etc \
    --localstatedir=/var \
    CPPFLAGS="${CPPFLAGS} -I/usr/include/ncursesw"
  make
}

package() {
  cd "${srcdir}"/$pkgname
  make DESTDIR="${pkgdir}" install

  install -d "${pkgdir}"/usr/share/licenses/tmux
  install -m 644 COPYING "${pkgdir}"/usr/share/licenses/tmux

  install -d "${pkgdir}"/usr/share/tmux
  install -m 644 examples/* "${pkgdir}"/usr/share/tmux
  install -d "${pkgdir}"/usr/share/vim/vimfiles/syntax
  install -m 644 examples/tmux.vim "${pkgdir}"/usr/share/vim/vimfiles/syntax

  install -d "${pkgdir}"/usr/share/bash-completion/completions/tmux
  mv "${pkgdir}"/usr/share/tmux/bash_completion_tmux.sh "${pkgdir}"/usr/share/bash-completion/completions/tmux
}
